//
//  MHComicIntroduct.m
//  ManHua
//
//  Created by 赵永泉 on 15/10/26.
//  Copyright © 2015年 蓝欧科技. All rights reserved.
//

#import "MHComicIntroduct.h"
#import <AFNetworking.h>

@implementation MHComicIntroduct
- (void)setValue:(id)value forKey:(NSString *)key
{
    [super setValue:value forKey:key];
    if ([key isEqualToString:@"desc"]) {
        self.BookDescription = value;
    }
    if ([key isEqualToString:@"dt_updated"]) {
        self.BookUpdateDate = value;
    }
    if ([key isEqualToString:@"title"]) {
        self.BookName = value;
    }
    if ([key isEqualToString:@"image_set_id"]) {
        [[AFHTTPRequestOperationManager manager] GET:[NSString stringWithFormat:@"https://pi.comikon.net/imagegroup/%@/autopick/", value] parameters:[NSDictionary dictionaryWithObjects:@[@"json", @"440", @"both", @"640"] forKeys:@[@"format", @"height", @"match", @"width"]] success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
            self.BookIconOtherURL = responseObject[@"image_url"];
            self.imageSize = CGSizeMake([responseObject[@"width"] floatValue], [responseObject[@"height"] floatValue]);
            [[NSNotificationCenter defaultCenter]postNotificationName:@"imageUrl" object:nil];
        } failure:^(AFHTTPRequestOperation * _Nonnull operation, NSError * _Nonnull error) {
            NSLog(@"%@", error.localizedDescription);
        }];
    }
    if ([key isEqualToString:@"objects"]) {
        self.BookID = [value[@"meta_id"] integerValue];
    }
    
    if ([key isEqualToString:@"comic_author"]) {
        self.BookAuthor = value;
    }
    if ([key isEqualToString:@"comic_name"]) {
        self.BookName = value;
    }
    if ([key isEqualToString:@"description"]) {
        self.BookDescription = value;
    }
    if ([key isEqualToString:@"resources"]) {
        self.resource_id = [value[0][@"resource_id"] integerValue];
    }
    if ([key isEqualToString:@"resources"]) {
        self.siteURL = value[0][@"site"][@"site_url"];
    }
    
}
@end
